package com.shenfa.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.shenfa.action.upload.DownloadAction;
import com.shenfa.bean.BillFodder;
import com.shenfa.bean.TreeNode;
import com.shenfa.service.BillFodderService;

import com.shenfa.util.ResultObject;

/**
 * 账单管理-素材管理 Action
 * 
 * @author 张瑶
 * @date 2011-08-24
 */
public class BillFodderAction extends BaseAction {

	private static final long serialVersionUID = 8237503040169904687L;
	@Autowired
	private BillFodderService billFodderService;
	private BillFodder billFodder;
	private static Logger log=Logger.getLogger(DownloadAction.class);
	/**
	 * 查询所有素材
	 * @return
	 */
	public String listField() {
		List<TreeNode> list = billFodderService.listField();
		result = ResultObject.build("0", list);
		return SUCCESS;
	}
	
	/**
	 * 模糊查询素材信息
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String selectBillFodder() {
		log.debug("billFodder="+billFodder);
		int skip = 0;
		int max = 10;
		List<BillFodder> list = billFodderService.selectBillFodder(billFodder, skip, max);
		result = ResultObject.build("0", list);
		result.put("total", 10);

		return SUCCESS;
	}

	/**
	 * 增加素材信息
	 * 
	 * @return
	 */
	public String insertBillFodder() {
		log.debug("billFodder="+billFodder);
		Object object = billFodderService.insertBillFodder(billFodder);
		if (null == object) {
			return ERROR;
		} else {
			return SUCCESS;
		}
	}

	/**
	 * 更新素材信息
	 * 
	 * @return
	 */
	public String updateBillFodder() {
		log.debug(billFodder.toString());
		int rows = billFodderService.updateBillFodder(billFodder);
		if (rows > 0) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	/**
	 * 刪除素材信息
	 * 
	 * @return
	 */
	public String deleteBillFodder() {
		log.debug("fodderNo="+billFodder.getFodderno());
		int rows = billFodderService.deleteBillFodder(billFodder);
		if (rows > 0) {
			return SUCCESS;
		} else {
			return ERROR;
		}
	}

	public BillFodder getBillFodder() {
		return billFodder;
	}

	public void setBillFodder(BillFodder billFodder) {
		this.billFodder = billFodder;
	}

}
